package com.javasm.mingming.upload;

import com.alibaba.excel.EasyExcel;
import com.javasm.mingming.test.entity.TestStudent;
import com.javasm.mingming.test.service.TestStudentService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.List;

/**
 * @author Administrator
 * @date 2025-01-19 10:55
 */
@RestController
@RequestMapping("/export")
public class ExportController {
    @Resource
    HttpServletResponse response;
    @Resource
    TestStudentService testStudentService;

@GetMapping("/stu/excel")
//导出全部数据
    public void exportStuExcel(){
    try {
        //获取需要导出信息
        List<TestStudent> list =
                testStudentService.list();
//    设置i相应头信息
        response.setContentType("appplication/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
        response.setCharacterEncoding("utf-8");
        //设置响应的头信息
        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
        response.setCharacterEncoding("utf-8");
//    写入
        EasyExcel.write(response.getOutputStream(), TestStudent.class).sheet("数据1").doWrite(list);

        response.getOutputStream().close();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }


}



}
